﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;
namespace Pixysoft.Framework.XSchEmA.Comparer
{
    class DataTableComparer : IDataTableCompareResult
    {
        List<TableSchema> aSuplusTables = new List<TableSchema>();
        List<TableSchema> bSuplusTables = new List<TableSchema>();
        List<KeyValuePair<TableSchema, TableSchema>> sameTables =
            new List<KeyValuePair<TableSchema, TableSchema>>();

        public IDataTableCompareResult Compare(DatabaseSchema aDatabase, DatabaseSchema bDatabase)
        {
            foreach (TableSchema aTable in aDatabase.Tables)
            {
                TableSchema bTable = bDatabase.GetTable(aTable.TableName);
                if (bTable != null)
                    sameTables.Add(new KeyValuePair<TableSchema, TableSchema>(aTable, bTable));
                else
                    aSuplusTables.Add(aTable);
            }

            foreach (TableSchema bTable in bDatabase.Tables)
            {
                TableSchema aTable = aDatabase.GetTable(bTable.TableName);
                if (aTable != null)
                    continue;
                else
                    bSuplusTables.Add(bTable);
            }

            return this;
        }

        public List<TableSchema> ASuplusTables
        {
            get { return aSuplusTables; }
        }

        public List<TableSchema> BSuplusTables
        {
            get { return bSuplusTables; }
        }

        public List<KeyValuePair<TableSchema, TableSchema>> SameTables
        {
            get { return sameTables; }
        }
    }
}
